/**
 * 
 */
package org.dragonfire.ti;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Darth Android
 * @date Sep 18, 2007
 */
public class Jabbit {

	public static final byte[] P = new byte[] {
			0x5B, 0x2E, 0x54, (byte) 0xE9, (byte) 0xB5, (byte) 0xC1, (byte) 0xFE, 0x26, (byte) 0xCE, (byte) 0x93, 0x26,
			0x14, 0x78, (byte) 0xD3, (byte) 0x87, 0x3F, 0x3F, (byte) 0xC4, 0x1B, (byte) 0xFF, (byte) 0xF1, (byte) 0xF5,
			(byte) 0xF9, 0x34, (byte) 0xD7, (byte) 0xA5, 0x79, 0x3A, 0x43, (byte) 0xC1, (byte) 0xC2, 0x1C
	};
	public static final byte[] Q = new byte[] {
			(byte) 0x97, (byte) 0xF7, 0x70, 0x7B, (byte) 0x94, 0x07, (byte) 0x9B, 0x73, (byte) 0x85, (byte) 0x87, 0x20,
			(byte) 0xBF, 0x6D, 0x49, 0x09, (byte) 0xAB, 0x3B, (byte) 0xED, (byte) 0xA1, (byte) 0xBA, (byte) 0x9B,
			(byte) 0x93, 0x11, 0x2B, 0x04, 0x13, 0x40, (byte) 0xA1, 0x6E, (byte) 0xD5, (byte) 0x97, (byte) 0xB6, 0x04
	};

	/**
	 * Generates a signature for the data. This algorithm is taken from wabbit
	 * and I have no clue how it actually works. This needs to be better
	 * understood so that it can be optimized for java.
	 * 
	 * @param data
	 * @return
	 */
	private static byte[] siggen(byte[] data) {
		try {
			MessageDigest md5Digest = MessageDigest.getInstance("MD5");
			md5Digest.reset();
			// m = md5hash
			byte[] md5Hash = md5Digest.digest(data);
			BigInteger m = new BigInteger(md5Hash);
			// M' = m*256+1
			BigInteger M = m.shiftLeft(8).add(BigInteger.ONE);
		} catch (NoSuchAlgorithmException ae) {
			throw new RuntimeException(
					"MD5 Hashing not supported on this platform, unable to generate application signature", ae);
		}
	}
}
